import os
import platform


def is_running_in_docker():
    # 方法1：检查环境变量
    if 'DOCKER' in os.environ:
        return True

    # 方法2：检查 /proc/1/cgroup
    try:
        with open('/proc/1/cgroup', 'rt') as ifh:
            text = ifh.read()
            return 'docker' in text.lower()
    except Exception:
        return False


redis_host = ''
if platform.system() == 'Windows' and is_running_in_docker():
    redis_host = 'host.docker.internal'
else:
    redis_host = 'localhost'


class PictureServiceConfig:
    """
    图片服务相关
    """
    SERVER_PATH = 'http://localhost/pics'
    ALGORITHM = 'BASE64'
    LINUX_STORAGE_PATH = '/data/www/pics'
    WINDOWS_STORAGE_PATH = 'D:\\data\\www\\pics'
    # PROJECT_PATH = project_path = os.path.join(os.path.dirname(__file__), '../')
    # LOCAL_SAVE_PATH = 'pics-server/'
    # SERVER_LOCAL_STORAGE_PATH = PROJECT_PATH.join(LOCAL_SAVE_PATH)


class ReviewsDefaultConfig:
    REVIEWS_AUTHOR = '微信用户'
    REVIEWS_AVATAR = 'https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132'
    DEFAULT_USER_ID = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMjAyNDk5MDAxMiIsInNlc3Npb25faWQiOiI1YWQ3ZDMzOS04ZTA5LTQ3MzEtYTJmZC1hMmM4M2Y2Y2ExZjEiLCJleHAiOjE3MTYwMTU4Njd9.RPnaBm1Z8M1JGpsbx8VUHZlDQWXbdEvi4EN0SjN_6Wc'


class JwtConfig:
    """
    Jwt配置
    """
    SECRET_KEY = "b01c66dc2c58dc6a0aabfe2144256be36226de378bf87f72c0c795dda67f4d55"
    ALGORITHM = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES = 1440
    REDIS_TOKEN_EXPIRE_MINUTES = 1 * 24 * 60 * 60


class DataBaseConfig:
    """
    数据库配置
    """
    HOST = '127.0.0.1'
    PORT = 5432
    USERNAME = 'postgres'
    PASSWORD = 'jraidy'
    DB = 'fei_campus_reviews'


class RedisConfig:
    """
    Redis配置
    """
    HOST = '127.0.0.1'
    PORT = 6379
    USERNAME = ''
    PASSWORD = ''
    DB = 0


class CachePathConfig:
    """
    缓存目录配置
    """
    PATH = os.path.join(os.path.abspath(os.getcwd()), 'caches')
    PATHSTR = 'caches'
